package sanrenxing.dayEnd.backRepertoryTotal.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import sanrenxing.dayEnd.backRepertoryTotal.domain.EquityData;
import sanrenxing.dayEnd.backRepertoryTotal.domain.EquityDataT;

import java.util.List;

/**
 * @desrciption 权益数据dao层
 * @auth：yidu  李小锋
 * @date:2021/3/13 0013 - 11:06
 * @version:1:0
 */
@Repository //标识为Spring中的Bean
public interface EquityDataDao {
    /**
     * 新增一行数据
     * @param equityData 对象
     * @return 0、增加失败 1、增加成功values(#{rightsId},#{seId},to_date('${rigDay}','yyyy-MM-dd'),to_date('${righDay}','yyyy-MM-dd'),to_date('${dueDate}','yyyy-MM-dd'),#{rigType},#{pro},#{proState},to_date('${businDate}','yyyy-MM-dd'))
     */
    @Insert("insert into equityData(rightsId,seId,rigDay,righDay,dueDate,rigType,pro,proState,businDate)" +
            "values(seqEquityData.nextval,#{seId},#{rigDay},#{righDay},#{dueDate},#{rigType},#{pro},#{proState},#{businDate})")
    public int add(EquityData equityData);

    /**
     * excl增一行数据
     * @param equityDataT 对象
     * @return 0、增加失败 1、增加成功values(#{rightsId},#{seId},to_date('${rigDay}','yyyy-MM-dd'),to_date('${righDay}','yyyy-MM-dd'),to_date('${dueDate}','yyyy-MM-dd'),#{rigType},#{pro},#{proState},to_date('${businDate}','yyyy-MM-dd'))
     */
    @Insert("insert into equityData(rightsId,seId,rigDay,righDay,dueDate,rigType,pro,proState,businDate)" +
            "values(#{rightsId},#{seId},to_date('${rigDay}','yyyy-MM-dd'),to_date('${righDay}','yyyy-MM-dd'),to_date('${dueDate}','yyyy-MM-dd'),#{rigType},#{pro},#{proState},to_date('${businDate}','yyyy-MM-dd'))")
    public int addExcl(EquityDataT equityDataT);
    /**
     * 删除一行数据
     * @param rightsId 编号
     * @return 0、删除失败 1、删除成功
     */
    @Delete("delete from equityData where rightsId=#{rightsId}")
    public int delete(@Param("rightsId") int rightsId);
    /**
     * 修改一行数据
     * @param equityData 对象
     * @return 0、修改失败 1、修改成功
     */
    @Update("update equityData set seId=#{seId},rigDay=#{rigDay},righDay=#{righDay},dueDate=#{dueDate}," +
            "rigType=#{rigType},pro=#{pro},proState=#{proState},businDate=#{businDate} " +
            "where rightsId=#{rightsId}")
    public int update(EquityData equityData);
    /**
     * 查询所有的订单数据
     * @return 返回一个订单集合
     */
    @Select("select * from equityData")
    @Results(id = "equityMap",value = {
            @Result(id = true,column = "rightsId",property = "rightsId"),
            @Result(column = "seId",property = "seId"),
            @Result(column = "rigDay",property = "rigDay"),
            @Result(column = "righDay",property = "righDay"),
            @Result(column = "dueDate",property = "dueDate"),
            @Result(column = "rigType",property = "rigType"),
            @Result(column = "pro",property = "pro"),
            @Result(column = "proState",property = "proState"),
            @Result(column = "businDate",property = "businDate")
    })
    public List<EquityData> findAll();
    /**
     * 分页查询
     * @param start  开始行号
     * @param rows   每页行数
     * @param condition 查询条件
     * @return 集合
     */
    @ResultMap(value = "equityMap")
    @Select("<script>"+
            "select * from " +
                "(select rownum  rn,equityData.* from equityData " +
                "<where> #{rows}>rownum </where>)"+
                "<where>"+
                /*"<if test='rn!=0'>"+*/
                " ${condition}"+
                /*"</if>"+*/
                " and rn>=#{start}"+
                "</where>"+
            "</script>")
    public List<EquityData> findByPage(@Param("start") int start, @Param("rows") int rows, @Param("condition") String condition);
    /**
     * 按条件统计出记录行数
     * @param condition 条件
     * @return 记录行数
     */
    @Select("select count(*) from equityData where 1=1  ${condition}")
    public int count(@Param("condition") String condition);
}
